<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>变换</title>
    <style>
        .trans {
            width: 300px;
            height: 80px;
            margin: 100px auto;
            background-color: deeppink;
            color: white;
            font-size: 40px;
            line-height: 80px;
            text-align: center;
            font-weight: 700;
            position: relative;
            transition: 2s;
        }

        .trans::before {
            content: "";
            display: block;
            position: absolute;
            width: 0;
            height: 10px;
            transition: width 2s;
            top: 0;
            left: 0;
            background-color: #9acd32;
        }

        .trans::after {
            content: "";
            display: block;
            position: absolute;
            width: 0;
            height: 10px;
            transition: 2s width;
            bottom: 0;
            right: 0;
            background-color: #9acd32;
        }

        .trans:hover {
            background-color: white;
            color: deeppink;
        }

        .trans:hover::before {
            width: 300px;
        }

        .trans:hover::after {
            width: 300px;
        }
    </style>
</head>

<body>
    <div class="trans">HTML5</div>
</body>

</html>